<template>
	<div class="testee_analysis">
		<el-table :data="tableData" stripe style="width: 100%">
			<el-table-column prop="sysUser" label="考题名称" min-width="240">
				<template slot-scope="{ row }">
					<span v-html="row.subjectInfo.title"></span>
				</template>
			</el-table-column>
			<el-table-column label="考生数量" width="90" align="center">
				<template slot-scope="{ row }">{{ row.total }} 个</template>
			</el-table-column>
			<el-table-column label="错题数量" width="90" align="center">
				<template slot-scope="{ row }">{{ row.error }} 个</template>
			</el-table-column>
			<el-table-column prop="createTime" label="错题率" min-width="180">
				<template slot-scope="{ row }"><el-progress :percentage="row | showPercentage"></el-progress></template>
			</el-table-column>
			<div slot="empty" class="emptyBg">
				<el-empty :image-size="100"></el-empty>
			</div>
		</el-table>
	</div>
</template>

<script>
import { testExamHisAnalyze } from '@/api/admin/exam/testExam';
export default {
	props: {
		examId: { type: String, default: '' }
	},
	data() {
		return {
			tableData: []
		};
	},
	filters: {
		showPercentage(data) {
			let total = parseInt(data.total);
			let error = parseInt(data.error);
			return Math.round((error / total) * 10000) / 100;
		}
	},
	watch: {
		examId: {
			handler(id) {
				this.getHistoryAnalyse(id);
			},
			immediate: true
		}
	},
	methods: {
		//获取历史考试分析
		async getHistoryAnalyse(id) {
			let result = await testExamHisAnalyze(id).then((res) => res.data);
			if (result.code === '0') {
				this.tableData = result.data || [];
			}
		}
	}
};
</script>

<style scoped></style>
